Skip to content

Fix unix socket half-close handling in Sockets#60961

Closed
abslock128w wants to merge 4 commits intoJuliaLang:masterfrom
abslock128w:fix/unix-socket-half-close
Closed

Fix unix socket half-close handling in Sockets#60961
abslock128w wants to merge 4 commits intoJuliaLang:masterfrom
abslock128w:fix/unix-socket-half-close

Conversation

@abslock128w
Copy link
Copy Markdown

Summary

Fix incorrect handling of unix domain socket half-close where a
PipeEndpoint was fully closed on UV_EOF, even when the write side
was still usable.

Problem

When libuv reports UV_EOF, Julia currently finalizes certain
LibuvStreams (notably PipeEndpoint) too aggressively.
This breaks valid half-close semantics, where the read side reaches EOF but the socket remains writable.
This behavior causes issues in clients that rely on
half-closed unix sockets, forcing workarounds such as splitting stdio
into multiple sockets.

Solution

Update uv_readcb to preserve the stream when the underlying handle
remains writable, allowing correct half-close behavior while still
closing truly unusable streams.

The change aligns Julia’s behavior with libuv semantics and POSIX
expectations.

Added tests for Unix domain socket half-close behavior.
Removed unnecessary checks for TTY and PipeEndpoint in EOF handling.
Handle stream closure for PipeEndpoint in UV_EOF case.
@tecosaur
Copy link
Copy Markdown
Member

tecosaur commented Feb 8, 2026

Ref: #60959

@abslock128w apologies if this is unfounded, but I get the sense that LLMs may have been used in formulating this PR. If this is the case, we would appreciate it if you would declare this.

@abslock128w
Copy link
Copy Markdown
Author

abslock128w commented Feb 8, 2026

Ref: #60959

@abslock128w apologies if this is unfounded, but I get the sense that LLMs may have been used in formulating this PR. If this is the case, we would appreciate it if you would declare this.

yeah I did use an LLM a bit while working on this, used it to understand the already writtne code
but the actual debugging, writing the test, and running the tests was done by me.
english isntt really my first language and its not that good...
so i usually use llm to translate what i want to say

@fingolfin fingolfin linked an issue Feb 9, 2026 that may be closed by this pull request
stream_unknown_type = @handle_as handle LibuvStream
nrequested = ccall(:jl_uv_buf_len, Csize_t, (Ptr{Cvoid},), buf)

function readcb_specialized(stream::LibuvStream, nread::Int, nrequested::UInt)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling "Hide whitespace" in the GitHub diff viewer, it seems to me that the changes to this function amount to:

  1. wrapping most of the code into a try/finally/end with unlock in the finalize block -- that seems plausible;
  2. inserting some empty lines, wrapping an overly long line -- I am neutral on this;
  3. removing or reducing a lot of comments -- that part seems less plausible: why do we want to remove comments or reduce them? Were they incorrect?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there,
Thank you for pointing out the mistake!
I am new to this whole open source contribution thing...
And about the comment part I never really use comments that's wrong on my part ( i know its a good practice to do so,
will try to keep that in mind as I move forward! )

Comment on lines -719 to -724
function reseteof(x::TTY)
iolock_begin()
if x.status == StatusEOF
x.status = StatusOpen
nothing
end
iolock_end()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is reseteof(x::TTY) being removed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mistakenly removed the TTY fucntion
This will probably brake the interactive input...
Will add in the next commit.
Again thank you for pointing it out!

@abslock128w abslock128w marked this pull request as draft February 28, 2026 05:54
@abslock128w abslock128w closed this by deleting the head repository Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unix domain sockets are prematurely closed after half-close

5 participants